﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace PulseApp
{
	/// <summary>
	/// Interaction logic for Page2.xaml
	/// </summary>
	public partial class Page4 : Page {



        Person person;

        Device device0;
        //public int currentPosition0 = 0;
        public ArrayList lines0 = new ArrayList();
        public Boolean isMonitoring0 = false;
        public int lastX0 = 0;
        public int lastY0 = 0;
        public int baseLine0 = 380;
        public PointCollection pc0;
        //public Polyline pl0;
        public PolyBezierSegment pbs0;
        public PathSegmentCollection psc0;
        public PathFigure pf0;
        public PathFigureCollection pfc0;
        public PathGeometry pg0;
        public Path path0;
        ArrayList pulseDataArray0;
        ArrayList tempDataArray0;
        PulseWave pulseWave0;

        Device device1;
        //public int currentPosition1 = 0;
        public ArrayList lines1 = new ArrayList();
        public Boolean isMonitoring1 = false;
        public int lastX1 = 0;
        public int lastY1 = 0;
        public int baseLine1 = 450;
        public PointCollection pc1;
        public Polyline pl1;
        public PolyBezierSegment pbs1;
        public PathSegmentCollection psc1;
        public PathFigure pf1;
        public PathFigureCollection pfc1;
        public PathGeometry pg1;
        public Path path1;
        ArrayList pulseDataArray1;
        ArrayList tembDataArray1;
        PulseWave pulseWave1;

        public ArrayList lines2 = new ArrayList();
        public int baseLine2 = 600;
        public PointCollection pc2;
        public Polyline pl2;
        public PolyBezierSegment pbs2;
        public PathSegmentCollection psc2;
        public PathFigure pf2;
        public PathFigureCollection pfc2;
        public PathGeometry pg2;
        public Path path2;
        ArrayList pulseDataArray2;
        ArrayList tembDataArray2;
        PulseWave pulseWave2;

        //UserWindow userWindow;
        ArrayList spLines = new ArrayList();// special point array;
        ArrayList tba = new ArrayList();//text block array

        Boolean isMonitoring = false;

        public double currentRate = 3.0;
        public int currentStart;

        public int height;
        public int pulseWaveRange = 2024;


        bool clicked = false;

        public static ArrayList age30 = new ArrayList{ 22, 23, 23, 22, 21, 23, 22, 21, 23, 22, 23, 26, 28, 33, 38, 46, 54, 64, 75, 88, 101, 113, 127, 140, 153, 165, 176, 186, 195, 202, 208, 212, 216, 219, 220, 220, 219, 217, 215, 213, 209, 206, 202, 198, 194, 191, 186, 182, 179, 174, 170, 167, 163, 159, 156, 154, 149, 146, 143, 139, 135, 131, 128, 124, 119, 116, 111, 106, 102, 97, 93, 88, 85, 81, 78, 75, 72, 70, 68, 66, 65, 64, 63, 63, 63, 63, 64, 65, 65, 66, 66, 67, 68, 68, 68, 69, 68, 69, 69, 69, 69, 68, 68, 67, 66, 66, 64, 63, 62, 61, 60, 59, 58, 56, 55, 54, 52, 50, 49, 47, 46, 45, 43, 43, 41, 40, 39, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 26, 25, 25, 24, 24, 23, 22, 23, 22, 22, 21, 21, 21, 20, 20, 20, 20, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 18, 18, 18, 18, 18, 17, 17, 17, 16, 16, 16, 16, 16, 15, 15, 15, 16, 17, 19, 22, 26, 32, 39, 47, 58, 69, 81, 95, 108, 122, 135, 148, 159, 171, 181, 189, 196, 202, 206, 209, 210, 211, 210, 210, 208, 205, 202, 199, 194, 191, 186, 183, 178, 174, 170, 166, 163, 159, 155, 152, 149, 146, 142, 139, 135, 133, 129, 125, 120, 117, 113, 108, 104, 99, 95, 90, 86, 83, 77, 75, 72, 69, 67, 65, 64, 63, 62, 61, 62, 62, 62, 63, 64, 65, 66, 67, 67, 68, 69, 70, 70, 71, 71, 71, 70, 70, 70, 69, 69, 68, 67, 66, 65, 64, 63, 61, 60, 59, 58, 57, 55, 54, 53, 51, 50, 49, 48, 46, 46, 44, 43, 43, 42, 40, 39, 38, 38, 36, 36, 35, 34, 33, 32, 32, 31, 30, 30, 29, 29, 28, 28, 27, 26, 26, 26, 25, 26, 25, 24, 25, 24, 24, 23, 24, 22, 23, 23, 24, 24, 23, 23, 24, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 22, 22, 22, 22, 21, 21, 22, 21, 21, 20, 21, 21, 21, 21, 21, 23, 25, 29, 34, 40, 48, 57, 68, 79, 92, 105, 118, 132, 145, 157, 169, 179, 188, 196, 203, 208, 212, 214, 216, 216, 216, 214, 213, 210, 206, 203, 199, 196, 192, 188, 184, 180, 177, 173, 169, 166, 162, 159, 155, 152, 149, 145, 143, 139, 136, 132, 129, 125, 121, 117, 113, 108, 104, 100, 95, 91, 87, 83, 80, 77, 74, 72, 70, 68, 67, 66, 65, 65, 65, 66, 66, 67, 67, 67, 68, 68, 70, 71, 70, 71, 72, 72, 72, 71, 71, 71, 70, 70, 70, 68, 67, 66, 65, 64, 63, 62, 60, 60, 58, 57, 56, 55, 53, 52, 51, 50, 48, 47, 46, 45, 44, 43, 41, 39, 40, 38, 37, 37, 36, 35, 34, 33, 33, 32, 31, 30, 30, 30, 29, 29, 28, 27, 27, 27, 26, 25, 25, 25, 24, 24, 24, 24, 24, 24, 23, 23, 24, 24, 23, 23, 24, 24, 24, 24, 25, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 23, 24, 23, 23, 23, 23, 23, 22, 22, 23, 23, 24, 26, 28, 32, 36, 43, 51, 61, 72, 85, 98, 110, 124, 137, 151, 163, 175, 185, 195, 203, 210, 214, 218, 220, 223, 222, 222, 220, 218, 216, 212, 209, 206, 202, 198, 194, 190, 186, 183, 179, 176, 172, 169, 166, 161, 159, 156, 153, 150, 147, 144, 139, 136, 132, 128, 124, 119, 115, 111, 106, 102, 97, 93, 89, 85, 82, 78, 75, 73, 71, 69, 68, 67, 66, 66, 66, 66, 67, 67, 68, 68, 69, 69, 70, 71, 71, 71, 71, 72, 72, 71, 71, 71, 70, 70, 69, 68, 67, 65, 64, 63, 61, 61, 59, 58, 57, 55, 54, 52, 51, 50, 48, 47, 46, 45, 44, 42, 41, 40, 39, 38, 36, 36, 35, 34, 34, 32, 32, 31, 30, 29, 29, 28, 28, 27, 27, 27, 26, 26, 25, 24, 24, 24, 23, 23, 23, 23, 22, 22, 23, 23, 22, 22, 23, 23, 22, 23, 22, 23, 22 };
        public static ArrayList age40 = new ArrayList { 48, 48, 48, 47, 46, 47, 46, 46, 46, 46, 47, 48, 50, 52, 55, 59, 63, 69, 74, 82, 89, 97, 105, 114, 122, 130, 139, 147, 154, 160, 165, 171, 174, 178, 180, 182, 182, 182, 181, 180, 178, 176, 173, 171, 168, 165, 163, 159, 157, 154, 152, 149, 147, 145, 143, 142, 140, 138, 137, 135, 133, 131, 130, 128, 126, 124, 123, 120, 118, 116, 115, 113, 112, 110, 109, 108, 108, 107, 106, 106, 107, 106, 107, 107, 107, 107, 108, 109, 108, 109, 109, 109, 109, 109, 108, 107, 107, 106, 105, 104, 103, 103, 101, 100, 100, 98, 96, 95, 94, 92, 91, 90, 89, 87, 86, 85, 84, 82, 81, 80, 79, 78, 78, 76, 76, 74, 74, 73, 72, 72, 71, 70, 70, 69, 69, 68, 68, 67, 67, 67, 67, 66, 66, 66, 66, 66, 66, 65, 65, 66, 65, 65, 65, 65, 64, 64, 64, 64, 63, 63, 62, 62, 62, 62, 62, 61, 61, 61, 60, 60, 60, 60, 59, 59, 59, 59, 59, 58, 58, 57, 57, 57, 57, 56, 55, 55, 54, 54, 53, 53, 53, 52, 52, 51, 51, 51, 50, 50, 49, 49, 50, 49, 50, 51, 52, 54, 56, 59, 64, 69, 74, 80, 87, 95, 102, 111, 120, 128, 136, 144, 151, 158, 164, 169, 174, 178, 181, 183, 184, 184, 183, 182, 180, 178, 176, 173, 170, 167, 164, 161, 158, 156, 153, 150, 148, 146, 143, 142, 140, 138, 136, 134, 133, 130, 128, 127, 125, 123, 121, 119, 117, 115, 113, 112, 111, 110, 109, 108, 107, 107, 106, 107, 107, 107, 108, 108, 109, 109, 110, 110, 111, 111, 112, 112, 112, 112, 112, 111, 111, 110, 109, 109, 107, 106, 106, 104, 103, 102, 100, 98, 97, 96, 94, 93, 92, 91, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80, 79, 79, 78, 78, 77, 76, 76, 76, 75, 75, 74, 73, 73, 73, 73, 72, 72, 71, 71, 71, 71, 71, 70, 70, 70, 70, 69, 69, 69, 69, 69, 68, 68, 68, 68, 68, 67, 67, 67, 67, 67, 67, 66, 66, 66, 65, 65, 65, 65, 64, 64, 63, 63, 63, 62, 61, 61, 60, 60, 58, 58, 58, 57, 57, 56, 55, 55, 55, 55, 55, 56, 57, 58, 61, 63, 67, 72, 77, 83, 89, 97, 104, 112, 119, 128, 135, 142, 149, 156, 162, 166, 171, 174, 177, 178, 179, 179, 179, 178, 176, 174, 172, 169, 167, 164, 161, 158, 156, 153, 150, 148, 146, 144, 142, 140, 138, 136, 134, 133, 131, 129, 127, 125, 123, 120, 118, 116, 114, 112, 110, 108, 107, 105, 104, 103, 102, 102, 102, 101, 102, 103, 103, 103, 103, 104, 105, 105, 106, 105, 106, 106, 107, 106, 107, 106, 105, 105, 103, 103, 102, 100, 99, 98, 97, 96, 95, 93, 91, 90, 89, 87, 87, 85, 84, 82, 82, 81, 79, 79, 78, 76, 76, 75, 74, 73, 73, 72, 71, 71, 70, 70, 69, 69, 69, 68, 68, 68, 67, 67, 67, 66, 66, 65, 65, 65, 65, 66, 65, 65, 64, 65, 64, 64, 64, 63, 63, 63, 63, 62, 62, 62, 62, 61, 61, 61, 61, 60, 60, 60, 59, 59, 59, 59, 59, 58, 58, 58, 57, 57, 57, 56, 55, 55, 54, 54, 54, 53, 52, 52, 52, 51, 51, 51, 51, 51, 52, 53, 55, 57, 60, 64, 69, 75, 81, 87, 96, 103, 112, 120, 128, 137, 145, 152, 159, 165, 170, 175, 178, 181, 183, 185, 185, 184, 184, 182, 181, 178, 176, 173, 171, 168, 165, 163, 160, 158, 155, 153, 151, 149, 147, 146, 144, 142, 140, 139, 138, 135, 134, 132, 130, 127, 125, 123, 121, 120, 118, 116, 115, 113, 112, 111, 110, 109, 110, 109, 109, 109, 109, 109, 110, 110, 111, 110, 111, 110, 110, 111, 111, 110, 110, 110, 110, 108, 107, 107, 106, 104, 103, 102, 100, 99, 98, 97, 95, 94, 93, 91, 90, 89, 87, 86, 85, 84, 82, 82, 80, 80, 79, 77 };
        public static ArrayList age50 = new ArrayList { 32, 32, 31, 30, 28, 28, 27, 26, 26, 27, 26, 24, 26, 25, 23, 24, 24, 23, 24, 24, 23, 22, 23, 23, 22, 23, 24, 25, 26, 29, 33, 37, 43, 50, 56, 66, 76, 85, 96, 105, 116, 125, 134, 142, 149, 156, 162, 167, 170, 173, 177, 178, 179, 181, 182, 180, 182, 180, 179, 178, 178, 175, 174, 173, 172, 169, 168, 168, 165, 164, 163, 161, 160, 159, 157, 155, 153, 152, 149, 147, 145, 142, 138, 136, 133, 129, 127, 125, 121, 118, 116, 114, 111, 110, 108, 105, 105, 104, 102, 101, 101, 101, 99, 100, 100, 97, 98, 98, 96, 95, 95, 94, 92, 92, 92, 89, 87, 87, 85, 83, 82, 80, 78, 76, 75, 72, 70, 69, 68, 65, 64, 62, 60, 58, 57, 55, 53, 52, 51, 49, 47, 47, 45, 43, 44, 42, 41, 41, 39, 38, 37, 38, 36, 35, 35, 34, 33, 34, 34, 33, 33, 33, 33, 31, 31, 32, 31, 31, 30, 29, 28, 29, 28, 26, 26, 25, 24, 24, 24, 23, 22, 23, 23, 22, 23, 25, 27, 29, 33, 39, 43, 51, 60, 68, 78, 89, 99, 109, 120, 129, 137, 146, 154, 159, 165, 170, 174, 177, 180, 182, 183, 183, 184, 183, 182, 182, 181, 180, 179, 178, 176, 175, 175, 172, 171, 170, 169, 166, 166, 164, 162, 160, 159, 156, 155, 153, 151, 147, 144, 142, 138, 134, 132, 129, 125, 122, 120, 116, 113, 111, 108, 105, 105, 103, 100, 99, 98, 97, 95, 96, 95, 94, 94, 94, 94, 93, 94, 92, 90, 91, 91, 88, 88, 87, 85, 83, 82, 81, 78, 78, 76, 73, 71, 70, 68, 65, 65, 63, 61, 60, 59, 56, 54, 54, 52, 51, 50, 50, 48, 47, 48, 47, 47, 47, 47, 46, 45, 46, 44, 44, 43, 42, 41, 41, 40, 39, 38, 38, 36, 36, 37, 35, 35, 35, 35, 34, 34, 34, 33, 31, 31, 31, 29, 30, 28, 26, 26, 25, 24, 24, 23, 23, 21, 22, 22, 22, 22, 24, 25, 26, 31, 35, 39, 44, 53, 60, 69, 80, 91, 99, 110, 120, 128, 137, 146, 153, 158, 163, 167, 170, 172, 175, 176, 175, 177, 176, 175, 175, 175, 172, 171, 171, 169, 167, 167, 165, 163, 163, 162, 160, 158, 158, 155, 154, 153, 151, 148, 146, 145, 141, 138, 136, 133, 129, 126, 124, 120, 117, 116, 113, 109, 108, 107, 104, 103, 104, 102, 101, 101, 101, 100, 100, 100, 100, 99, 100, 99, 98, 98, 98, 96, 96, 95, 93, 92, 92, 89, 87, 86, 85, 82, 80, 79, 75, 73, 72, 70, 68, 65, 65, 62, 59, 59, 57, 54, 54, 53, 51, 49, 49, 47, 45, 45, 44, 41, 42, 41, 39, 40, 39, 38, 37, 37, 37, 35, 35, 35, 34, 33, 33, 33, 32, 32, 32, 30, 29, 30, 29, 28, 29, 28, 26, 26, 26, 25, 24, 25, 23, 22, 24, 24, 24, 25, 28, 30, 32, 38, 43, 49, 57, 66, 74, 84, 95, 105, 114, 124, 132, 139, 148, 154, 159, 164, 168, 171, 172, 176, 176, 176, 177, 177, 176, 176, 176, 175, 172, 172, 170, 167, 166, 166, 164, 161, 162, 160, 157, 157, 157, 154, 153, 152, 149, 146, 145, 142, 138, 135, 132, 130, 126, 123, 121, 117, 115, 113, 109, 108, 106, 105, 102, 101, 101, 99, 98, 98, 97, 96, 96, 96, 94, 95, 95, 93, 93, 92, 91, 91, 90, 89, 87, 85, 85, 82, 80, 79, 77, 75, 73, 72, 69, 67, 66, 63, 60, 61, 58, 56, 54, 54, 50, 49, 48, 46, 44, 44, 42, 40, 40, 40, 37, 37, 36, 35, 33, 33, 33, 32, 31, 31, 29, 28, 29, 28, 27, 27, 27, 26, 25, 27, 25, 24, 25, 24, 23, 23, 24, 22, 22, 22, 22, 20, 21, 22, 20, 20, 20, 20, 18, 18, 18, 16, 17, 17, 15, 15, 16, 15, 15, 15, 16, 16, 18, 20, 22, 25, 29, 34, 40, 48, 57, 65, 75, 86, 97, 107, 118, 128, 136, 144, 153, 157, 163, 168, 172, 174, 177, 179, 179, 180, 181, 181, 180, 180, 179, 177, 177, 177, 174, 173, 173, 171, 170, 169, 168, 167, 166, 165, 164, 162, 162, 160, 157, 155, 153, 150, 148, 146, 142, 138, 137, 134, 129, 127, 125, 121, 119, 118, 115, 112, 112, 110, 108, 107, 106, 105, 103, 104, 102, 102, 101, 101, 100, 99, 99, 98, 97, 96, 95, 93, 92, 90, 89, 87, 86, 84, 82, 81, 79, 76, 75, 73, 71, 68, 67, 66, 63, 62, 59, 57, 55, 54, 52, 50, 50, 48, 46, 45, 45, 42, 41, 41, 39, 38, 37, 36, 35, 34, 34, 33, 31, 31, 31, 29, 30, 29, 28, 27, 27, 27, 26, 26, 26, 25, 25, 26, 25, 24, 25, 25, 24, 25, 24, 23, 23, 23, 22, 22, 22, 21, 20, 20, 20, 18, 18, 18, 18, 17, 17, 17, 17, 17, 18, 19, 19, 22, 26, 28, 32, 39, 44, 51, 60, 69, 77, 88, 99, 108, 118, 128, 136, 143, 151, 156, 160, 165, 169, 170, 172, 174, 174, 174, 175, 175, 172, 172, 172, 171, 169, 168, 167, 165, 164, 163, 161, 160, 159, 157, 155, 155, 155, 152, 150, 149, 147, 145, 143, 141, 136, 135, 131, 127, 125, 123, 119, 116, 114, 111, 108, 106, 104, 102, 100, 99, 98, 96, 96, 95, 93, 93, 93, 91, 91, 91, 89, 89, 88, 87, 86, 84, 83, 82, 79 };
        public static ArrayList age70 = new ArrayList { 37, 37, 37, 37, 36, 37, 38, 38, 38, 39, 39, 39, 39, 41, 40, 40, 41, 41, 41, 41, 42, 42, 41, 42, 42, 42, 42, 43, 42, 42, 42, 43, 42, 43, 43, 43, 44, 44, 44, 44, 44, 45, 45, 45, 45, 46, 46, 46, 46, 46, 47, 47, 47, 47, 48, 47, 47, 48, 46, 46, 46, 45, 45, 45, 47, 48, 51, 57, 62, 69, 76, 84, 91, 98, 106, 112, 118, 124, 130, 134, 139, 144, 147, 150, 154, 156, 158, 160, 162, 163, 164, 165, 165, 165, 165, 165, 165, 164, 163, 162, 160, 159, 157, 153, 150, 147, 143, 139, 135, 130, 125, 120, 117, 112, 108, 104, 100, 97, 94, 91, 88, 85, 83, 81, 80, 78, 78, 76, 76, 76, 76, 75, 74, 74, 74, 74, 72, 72, 71, 70, 69, 68, 68, 66, 65, 65, 64, 63, 62, 60, 59, 59, 58, 56, 55, 54, 54, 52, 51, 51, 50, 50, 49, 49, 48, 47, 47, 46, 45, 45, 45, 44, 44, 43, 42, 42, 42, 41, 41, 40, 41, 40, 40, 40, 40, 40, 39, 40, 40, 41, 41, 42, 42, 43, 43, 43, 43, 43, 43, 43, 43, 44, 43, 44, 44, 43, 43, 44, 43, 43, 43, 43, 43, 43, 43, 42, 43, 42, 43, 43, 43, 44, 44, 44, 45, 45, 46, 47, 47, 47, 47, 48, 47, 47, 47, 47, 47, 46, 46, 45, 46, 47, 49, 52, 57, 63, 70, 77, 85, 94, 102, 109, 117, 124, 131, 138, 143, 150, 156, 160, 165, 169, 172, 176, 179, 181, 183, 185, 186, 186, 187, 188, 187, 187, 186, 185, 183, 182, 180, 178, 175, 172, 168, 165, 160, 155, 150, 146, 140, 136, 130, 125, 120, 116, 112, 108, 103, 101, 97, 94, 92, 90, 88, 86, 85, 84, 83, 82, 82, 81, 80, 80, 79, 79, 78, 79, 78, 78, 78, 77, 76, 76, 76, 73, 74, 73, 71, 70, 68, 67, 66, 64, 63, 61, 59, 58, 56, 55, 52, 51, 50, 48, 47, 46, 45, 44, 44, 43, 43, 42, 42, 41, 41, 41, 41, 41, 40, 39, 40, 40, 39, 39, 39, 38, 38, 38, 38, 37, 37, 39, 39, 38, 39, 39, 40, 40, 40, 41, 41, 41, 42, 41, 42, 43, 43, 43, 43, 44, 44, 44, 44, 44, 44, 44, 44, 44, 43, 43, 44, 44, 44, 44, 44, 44, 45, 44, 45, 45, 45, 45, 46, 46, 46, 46, 46, 46, 47, 47, 47, 48, 49, 52, 57, 62, 69, 76, 85, 93, 101, 109, 119, 126, 134, 141, 149, 155, 162, 169, 174, 180, 186, 190, 195, 198, 201, 204, 206, 207, 209, 210, 211, 212, 211, 212, 212, 211, 210, 210, 207, 204, 203, 198, 194, 190, 185, 179, 173, 167, 160, 153, 146, 141, 133, 127, 123, 117, 112, 108, 104, 100, 98, 96, 94, 92, 90, 89, 88, 87, 86, 85, 85, 84, 83, 82, 82, 81, 80, 79, 78, 76, 76, 75, 73, 72, 71, 69, 67, 66, 64, 63, 61, 60, 59, 56, 56, 55, 52, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 42, 41, 40, 39, 39, 38, 37, 36, 35, 34, 34, 33, 32, 31, 31, 31, 30, 31, 30, 30, 30, 30, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 30, 29, 30, 30, 31, 31, 31, 32, 32, 32, 33, 32, 32, 33, 33, 33, 33, 33, 33, 33, 34, 34, 34, 34, 35, 34, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 34, 34, 34, 34, 35, 36, 37, 40, 44, 50, 57, 65, 72, 82, 91, 99, 109, 118, 127, 135, 144, 151, 159, 167, 173, 180, 186, 192, 196, 201, 205, 208, 211, 213, 215, 216, 217, 218, 219, 218, 218, 218, 217, 216, 215, 212, 209, 206, 202, 197, 191, 186, 180, 174, 167, 160, 153, 147, 140, 133, 127, 123, 116, 112, 108, 105, 101, 99, 96, 93, 91, 91, 89, 88, 87, 86, 85, 84, 83, 82, 81, 81, 80, 79, 78, 78, 76, 76, 75, 73, 73, 72, 71, 70, 68, 67, 65, 64, 62, 61, 59, 57, 57, 55, 54, 52, 51, 50, 48, 47, 46, 44, 44, 42, 41, 40, 40, 39, 38, 38, 37 };
        public static ArrayList ageOlder = new ArrayList { 50, 49, 49, 49, 48, 49, 48, 50, 50, 51, 52, 54, 56, 60, 62, 66, 71, 77, 81, 88, 93, 100, 106, 112, 118, 124, 130, 135, 141, 147, 153, 158, 163, 168, 173, 178, 182, 186, 190, 195, 199, 200, 204, 207, 208, 211, 212, 212, 215, 215, 216, 216, 217, 217, 217, 216, 217, 216, 216, 213, 211, 208, 206, 204, 201, 199, 197, 193, 191, 188, 185, 184, 181, 179, 177, 174, 172, 169, 167, 164, 163, 161, 159, 157, 155, 153, 152, 150, 148, 147, 144, 143, 141, 139, 138, 136, 134, 132, 132, 129, 128, 127, 124, 124, 123, 121, 120, 118, 116, 115, 113, 111, 109, 108, 107, 106, 105, 104, 102, 101, 100, 98, 96, 96, 94, 93, 92, 91, 88, 88, 86, 84, 84, 83, 82, 81, 80, 79, 76, 76, 75, 73, 74, 72, 71, 70, 69, 68, 67, 68, 66, 66, 65, 64, 62, 62, 62, 61, 61, 60, 58, 57, 58, 56, 56, 56, 55, 55, 55, 54, 52, 53, 52, 51, 51, 50, 49, 49, 48, 48, 48, 47, 47, 47, 46, 48, 45, 46, 45, 46, 46, 48, 49, 49, 56, 57, 62, 66, 70, 76, 82, 87, 93, 99, 105, 111, 117, 122, 128, 133, 137, 144, 149, 154, 159, 164, 167, 172, 177, 180, 183, 185, 188, 190, 193, 195, 195, 199, 200, 202, 203, 204, 203, 202, 205, 203, 202, 202, 201, 196, 197, 195, 192, 191, 189, 187, 184, 182, 180, 177, 175, 172, 169, 166, 164, 161, 161, 158, 155, 153, 151, 150, 148, 146, 144, 142, 140, 139, 136, 135, 133, 132, 129, 128, 127, 125, 123, 120, 121, 119, 118, 117, 115, 113, 112, 111, 108, 106, 106, 104, 103, 103, 100, 100, 98, 96, 96, 94, 92, 91, 90, 88, 87, 85, 83, 82, 81, 80, 79, 78, 78, 76, 75, 73, 71, 72, 69, 69, 67, 67, 66, 64, 63, 63, 63, 62, 61, 60, 59, 58, 56, 56, 55, 55, 55, 53, 52, 51, 52, 51, 51, 50, 51, 49, 48, 48, 47, 47, 46, 45, 45, 45, 44, 44, 42, 42, 41, 43, 41, 41, 41, 40, 39, 38, 38, 38, 37, 37, 36, 36, 37, 38, 39, 42, 44, 47, 51, 55, 61, 65, 70, 75, 81, 87, 93, 100, 105, 112, 116, 124, 128, 135, 140, 144, 149, 153, 158, 162, 165, 169, 172, 175, 179, 181, 184, 187, 188, 191, 191, 193, 193, 194, 194, 195, 194, 193, 193, 192, 191, 189, 188, 186, 184, 182, 181, 178, 176, 174, 171, 168, 167, 163, 162, 160, 159, 156, 155, 152, 153, 151, 149, 147, 145, 146, 143, 141, 139, 138, 137, 135, 133, 132, 131, 130, 129, 128, 126, 127, 125, 123, 122, 121, 119, 118, 116, 115, 114, 113, 112, 111, 110, 109, 108, 106, 106, 104, 103, 101, 99, 99, 98, 96, 96, 95, 93, 93, 93, 90, 90, 89, 87, 86, 84, 85, 83, 81, 81, 78, 79, 78, 79, 77, 76, 76, 75, 74, 73, 73, 71, 71, 69, 69, 68, 67, 67, 66, 66, 65, 65, 64, 64, 63, 63, 61, 62, 60, 60, 59, 59, 58, 59, 58, 57, 58, 57, 56, 56, 56, 56, 55, 54, 55, 54, 54, 53, 53, 53, 53, 52, 51, 52, 53, 55, 57, 59, 61, 65, 70, 74, 79, 84, 89, 96, 102, 108, 114, 120, 126, 132, 138, 144, 150, 157, 161, 166, 172, 176, 182, 185, 191, 195, 200, 204, 208, 211, 214, 218, 219, 221, 222, 224, 226, 227, 228, 228, 230, 229, 230, 230, 230, 229, 227, 226, 224, 222, 221, 219, 215, 214, 211, 208, 206, 204, 201, 197, 195, 193, 191, 188, 185, 183, 180, 178, 176, 173, 171, 170, 167, 165, 163, 162, 160, 158, 156, 155, 152, 151, 149, 147, 146, 144, 142, 141, 139, 137, 136, 135, 133, 131, 130, 127, 126, 125, 122, 121, 119, 118, 116, 115, 115, 112, 112, 110, 108, 107, 105, 105, 102, 103, 100, 99 };

        PulseWave[] pulseSamples = { new PulseWave(age30, 170), new PulseWave(age40, 170), new PulseWave(age50, 170),
                                   new PulseWave(age70, 170),new PulseWave(ageOlder, 170)};
        int DTWSelection = 0;


        public void setSamples()
        {
            pulseSamples[0].age = 30;
            pulseSamples[1].age = 40;
            pulseSamples[2].age = 50;
            pulseSamples[3].age = 60;
            pulseSamples[4].age = 70;
            pulseSamples[0].description = "low risk";
            pulseSamples[1].description = "low risk";
            pulseSamples[2].description = "middle risk";
            pulseSamples[3].description = "middle risk";
            pulseSamples[4].description = "high risk";
            foreach (PulseWave pulseWaveSample in pulseSamples) pulseWaveSample.getSIs();
        }

        public void resetWaveForm()
        {
            lines0 = new ArrayList();
        
        lastX0 = 0;
        lastY0 = 0;
        baseLine0 = 500;
        pc0=new PointCollection();
        //public Polyline pl0;
         pbs0= new PolyBezierSegment();
         psc0=new  PathSegmentCollection();
         pf0=new PathFigure();
         pfc0 = new PathFigureCollection();
        pg0 = new PathGeometry();
        path0 = new Path();
        }


		public Page4() {
			InitializeComponent();
            setSamples();
            myDataSet = (pulseDataSet)(this.FindResource("pulseDataSet"));
            myAdapter = new pulseDataSetTableAdapters.monitoringTableAdapter();
            myAdapter.Fill(myDataSet.monitoring);
            myDataSet.monitoring.Select("personID = " + CommonResources.Instance.getPerson().getId());
            System.Windows.Data.CollectionViewSource monitoringViewSource = ((System.Windows.Data.CollectionViewSource)(this.FindResource("monitoringViewSource")));
            monitoringViewSource.Source = myDataSet.monitoring.Select("personID = " + CommonResources.Instance.getPerson().getId());
            this.resultTextBlock.Text = CommonResources.Instance.getPerson().toResult();
            Person thePerson = CommonResources.Instance.getPerson();
            this.pulseDataArray1 = new ArrayList();
            if (thePerson.Age < 30)
            {
                this.pulseDataArray1 = age30;
            }
            else if (thePerson.Age < 40)
            {
                this.pulseDataArray1 = age40;
            }
            else if (thePerson.Age < 50)
            {
                this.pulseDataArray1 = age50;
            }
            else if (thePerson.Age < 70)
            {
                this.pulseDataArray1 = age70;
            }
            else
            {
                this.pulseDataArray1 = ageOlder;
            }
            double[] range = CommonResources.Instance.getSILevel(thePerson.getAge());

            //Console.WriteLine("before get pulse wave, pulsedataarray1: " + pulseDataArray1.Count + " height: " + CommonResources.Instance.getPerson().getHeight());
            PulseWave agePulseWave = new PulseWave(pulseDataArray1, CommonResources.Instance.getPerson().getHeight());
            if (agePulseWave.getFirstWaveformDataArray()!=null) this.pulseDataArray1 = agePulseWave.getFirstWaveformDataArray();
            //Console.WriteLine("firs wave form points count: " + agePulseWave.SIsToString());
            Canvas.SetLeft(labelSample, pulseDataArray1.Count+20);
            this.labelSample.Text += range[0] + "--" + range[1];
            if (this.dataGrid1.Items.Count > 0)
            {
                pulseDataSet.monitoringRow currentRow = myDataSet.monitoring.NewmonitoringRow();
                currentRow = (pulseDataSet.monitoringRow)dataGrid1.SelectedItem;
                if (currentRow.pulse_data != null)
                {
                    pulseWave0 = new PulseWave((byte[])currentRow.pulse_data, CommonResources.Instance.getPerson().getHeight());
                    pulseDataArray0 = pulseWave0.getPulseDataArray();

                    pulseWave0.getSIs();
                    setDTW();
                    
                    drawWaves();
                    this.resultTextBlock.Text += "\r\n" + pulseWave0.toResult();
                }
            }
            //clicked = true;
		}


        private void Page_MouseMove(object sender, MouseEventArgs e){
            clicked = true;
        }

		private void Page_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) {
			//NavigationService.Navigate(new Uri("Index.xaml", UriKind.Relative));
            this.clicked = true;
            //this.resultTextBlock.Text += "clicked!    ";
		}

        public void clearLines()
        {
            if (this.lines0.Count > 0)
            {
                foreach (Line aLine in lines0)
                {
                    this.pulseCanvas.Children.Remove(aLine);
                }
            }
            if (this.lines1.Count > 0)
            {
                foreach (Line aLine in lines1)
                {
                    this.pulseCanvas.Children.Remove(aLine);
                }
            }
            if (this.lines2.Count > 0)
            {
                foreach (Line aLine in lines2)
                {
                    this.pulseCanvas.Children.Remove(aLine);
                }
            }
        }

        public void drawWave(int id)
        {
            if (id == 0)
            {
                this.pbs0 = new PolyBezierSegment();
                this.pc0 = new PointCollection();
                this.psc0 = new PathSegmentCollection();
                this.pf0 = new PathFigure();
                this.pfc0 = new PathFigureCollection();
                this.pg0 = new PathGeometry();
                this.path0 = new Path();
                int count = 0;
                for (int i = pulseDataArray0.Count - (int)pulseCanvas.Width; i < pulseDataArray0.Count; i++)
                {
                    Point aPoint = new Point(count, baseLine0 - (short)pulseDataArray0[i]);
                    pc0.Add(aPoint);
                    count++;
                }
                pbs0.Points = pc0;
                //Console.WriteLine(pc0.Count);
                this.psc0.Add(pbs0);
                pf0.Segments = psc0;
                pfc0.Add(pf0);
                pg0.Figures = pfc0;
                path0.Data = pg0;
                path0.Stroke = Brushes.White;
                path0.StrokeThickness = 2;
                this.pulseCanvas.Children.Add(path0);
                this.pulseCanvas.UpdateLayout();
            }
            else if (id == 1)
            {
                this.pbs1 = new PolyBezierSegment();
                this.pc1 = new PointCollection();
                this.psc1 = new PathSegmentCollection();
                this.pf1 = new PathFigure();
                this.pfc1 = new PathFigureCollection();
                this.pg1 = new PathGeometry();
                this.path1 = new Path();
                int count = 0;
                for (int i = 0; i < pulseDataArray1.Count && i<738; i++)
                {
                    Point aPoint = new Point(count, baseLine1 - int.Parse(pulseDataArray1[i].ToString()));
                    pc1.Add(aPoint);
                    count++;
                }
                pbs1.Points = pc1;
                Console.WriteLine(pc1.Count);
                this.psc1.Add(pbs1);
                pf1.Segments = psc1;
                pfc1.Add(pf1);
                pg1.Figures = pfc1;
                path1.Data = pg1;
                path1.Stroke = Brushes.White;
                path1.StrokeThickness = 2;
                this.pulseCanvas.Children.Add(path1);
                this.pulseCanvas.UpdateLayout();
            }
            else if (id == 2)
            {
                this.pbs2 = new PolyBezierSegment();
                this.pc2 = new PointCollection();
                this.psc2 = new PathSegmentCollection();
                this.pf2 = new PathFigure();
                this.pfc2 = new PathFigureCollection();
                this.pg2 = new PathGeometry();
                this.path2 = new Path();
                int count = 0;
                pc2.Clear();
                for (int i = 0; i < pulseDataArray2.Count && i < 738; i++)
                {
                    Point aPoint = new Point(count, baseLine2 - int.Parse(pulseDataArray2[i].ToString()));
                    pc2.Add(aPoint);
                    count++;
                }
                pbs2.Points = pc2;
                Console.WriteLine(pc2.Count);
                this.psc2.Add(pbs2);
                pf2.Segments = psc2;
                pfc2.Add(pf2);
                pg2.Figures = pfc2;
                path2.Data = pg2;
                path2.Stroke = Brushes.White;
                path2.StrokeThickness = 2;
                this.pulseCanvas.Children.Add(path2);
                this.pulseCanvas.UpdateLayout();
            }
        }

        public void clearSPLines()
        {
            if (this.spLines.Count > 0)
            {
                foreach (Line line in spLines)
                {
                    this.pulseCanvas.Children.Remove(line);
                }
            }
        }

        public void clearTextBlocks()
        {
            if (this.tba.Count > 0)
            {
                foreach (TextBlock tb in tba)
                {
                    this.pulseCanvas.Children.Remove(tb);
                }
            }
        }

        public Boolean earlyWaveOnTop()
        {
            Boolean result = true;
            if (this.pulseWave0 != null && this.pulseWave1 != null)
            {
                for (int i = 2; i < pulseWave0.getSpecialPoints().Count; i++)
                {
                    SpecialPoint spi = ((SpecialPoint)pulseWave0.getSpecialPoints()[i]);
                    if (spi.getType() == SpecialPoint.TYPE_BOTTOM)
                    {
                        int earlyBottom = 0;
                        int laterBottom = 0;
                        for (int j = 0; j < pulseWave1.getSpecialPoints().Count; j++)
                        {
                            SpecialPoint spj = ((SpecialPoint)pulseWave1.getSpecialPoints()[j]);
                            if (spj.getType() == SpecialPoint.TYPE_BOTTOM && spj.getPosition() < spi.getPosition())
                            {
                                earlyBottom = j;
                            }
                            else if (spj.getType() == SpecialPoint.TYPE_BOTTOM && spj.getPosition() > spi.getPosition())
                            {
                                laterBottom = j;
                                break;
                            }
                        }
                        if (((SpecialPoint)pulseWave1.getSpecialPoints()[laterBottom]).getPosition() - ((SpecialPoint)pulseWave0.getSpecialPoints()[i]).getPosition() >
                            ((SpecialPoint)pulseWave0.getSpecialPoints()[i]).getPosition() - ((SpecialPoint)pulseWave1.getSpecialPoints()[earlyBottom]).getPosition())
                        {
                            result = false;
                        }
                        break;
                    }
                }
            }
            return result;
        }


        public void drawWaveSegment(int id, int start, double rate)
        {

            //check the zoom rate
            short heighest = 0;
            short lowest = 255;
            double margins = 0.1;
            for (int i = pulseDataArray0.Count - (int)pulseCanvas.Width; i < pulseDataArray0.Count; i++)
            {
                if ((short)pulseDataArray0[i] > heighest) heighest = (short)pulseDataArray0[i];
                if ((short)pulseDataArray0[i] < lowest) lowest = (short)pulseDataArray0[i];
                if (pulseDataArray1 != null && pulseDataArray1.Count > i && (short)pulseDataArray1[i] > heighest) heighest = (short)pulseDataArray1[i];
                if (pulseDataArray1 != null && pulseDataArray1.Count > i && (short)pulseDataArray1[i] < lowest) lowest = (short)pulseDataArray1[i];
            }
            if (rate > (1 - margins) * this.pulseCanvas.Height / ((double)heighest - (double)lowest))
            {
                rate = (1 - margins) * this.pulseCanvas.Height / ((double)heighest - (double)lowest);
                currentRate = rate;
            }
            //check the end point
            int end = start + (int)(pulseCanvas.Width / rate);
            if (end >= this.pulseDataArray0.Count) end = pulseDataArray0.Count - 1;
            if (pulseDataArray1 != null && end >= this.pulseDataArray1.Count) end = pulseDataArray1.Count - 1;

            Boolean earlyontop = this.earlyWaveOnTop();

            //get arm length
            double armLength = 70;
            /*if (this.userWindow != null && userWindow.user != null && userWindow.user.getArmLength() > 0)
            {
                armLength = userWindow.user.getArmLength();
            }*/
            armLength = armLength / 100; //convert to meter


            if (id == 0)
            {
                this.pbs0 = new PolyBezierSegment();
                this.pc0 = new PointCollection();
                this.psc0 = new PathSegmentCollection();
                this.pf0 = new PathFigure();
                this.pfc0 = new PathFigureCollection();
                this.pg0 = new PathGeometry();
                this.path0 = new Path();
                int count = 0;
                for (int i = start; i < end; i++)
                {
                    Point aPoint = new Point(count * rate, baseLine1 - 30 - ((short)pulseDataArray0[i] - (double)lowest) * rate);
                    pc0.Add(aPoint);
                    count++;
                }
                pbs0.Points = pc0;
                Console.WriteLine(pc0.Count);
                this.psc0.Add(pbs0);
                pf0.Segments = psc0;
                pfc0.Add(pf0);
                pg0.Figures = pfc0;
                path0.Data = pg0;
                path0.Stroke = Brushes.White;
                path0.StrokeThickness = 2;
                if (currentRate > 2) path0.StrokeThickness = 4;
                this.pulseCanvas.Children.Add(path0);
                this.pulseCanvas.UpdateLayout();



                //draw bottom lines
                clearSPLines();
                clearTextBlocks();
                foreach (SpecialPoint sp in this.pulseWave0.getSpecialPoints())
                {
                    if (sp.getType() == SpecialPoint.TYPE_BOTTOM && sp.getPosition() > start && sp.getPosition() < end)
                    {
                        double xValue = (sp.getPosition() - start) * rate;
                        Line aLine = new Line();
                        aLine.X1 = xValue;
                        aLine.X2 = xValue;
                        aLine.Y1 = 0;
                        aLine.Y2 = baseLine1;
                        aLine.Stroke = Brushes.Red;
                        spLines.Add(aLine);

                        //set text
                        TextBlock tb = new TextBlock();
                        tb.FontSize = 14;
                        tb.Text = sp.getPosition() + "";
                        if (earlyontop && pulseDataArray1 != null)
                        {
                            SpecialPoint sp1 = new SpecialPoint();
                            for (int j = 0; j < pulseWave1.getSpecialPoints().Count; j++)
                            {
                                SpecialPoint spj = ((SpecialPoint)pulseWave1.getSpecialPoints()[j]);
                                if (spj.getType() == SpecialPoint.TYPE_BOTTOM && spj.getPosition() > sp.getPosition())
                                {
                                    sp1 = spj;
                                    break;
                                }
                            }
                            tb.Text = sp.getPosition() + "\r\nArm length is " + armLength +
                                "M\r\nPWV is " + armLength * 200 / (sp1.getPosition() - sp.getPosition());
                        }
                        Canvas.SetTop(tb, baseLine1 - 30 - (short)pulseDataArray0[sp.getPosition()]);
                        Canvas.SetLeft(tb, xValue + 5);
                        this.tba.Add(tb);

                        //add elements
                        this.pulseCanvas.Children.Add(tb);
                        this.pulseCanvas.Children.Add(aLine);
                    }
                }
            }
            else if (id == 1 && pulseDataArray1 != null)
            {
                this.pbs1 = new PolyBezierSegment();
                this.pc1 = new PointCollection();
                this.psc1 = new PathSegmentCollection();
                this.pf1 = new PathFigure();
                this.pfc1 = new PathFigureCollection();
                this.pg1 = new PathGeometry();
                this.path1 = new Path();
                int count = 0;
                for (int i = start; i < end; i++)
                {
                    Point aPoint = new Point(count * rate, baseLine1 - ((short)pulseDataArray1[i] - (double)lowest) * rate);
                    pc1.Add(aPoint);
                    count++;
                }
                pbs1.Points = pc1;
                Console.WriteLine(pc1.Count);
                this.psc1.Add(pbs1);
                pf1.Segments = psc1;
                pfc1.Add(pf1);
                pg1.Figures = pfc1;
                path1.Data = pg1;
                path1.Stroke = Brushes.Blue;
                path1.StrokeThickness = 2;
                if (currentRate > 2) path1.StrokeThickness = 4;
                this.pulseCanvas.Children.Add(path1);
                this.pulseCanvas.UpdateLayout();

                foreach (SpecialPoint sp in this.pulseWave1.getSpecialPoints())
                {
                    if (sp.getType() == SpecialPoint.TYPE_BOTTOM && sp.getPosition() > start && sp.getPosition() < end)
                    {
                        double xValue = (sp.getPosition() - start) * rate;
                        Line aLine = new Line();
                        aLine.X1 = xValue;
                        aLine.X2 = xValue;
                        aLine.Y1 = 0;
                        aLine.Y2 = baseLine1;
                        aLine.Stroke = Brushes.Red;
                        spLines.Add(aLine);
                        TextBlock tb = new TextBlock();
                        tb.FontSize = 14;
                        tb.Text = sp.getPosition() + "";
                        if (!earlyontop)
                        {
                            SpecialPoint sp0 = new SpecialPoint();
                            for (int j = 0; j < pulseWave0.getSpecialPoints().Count; j++)
                            {
                                SpecialPoint spj = ((SpecialPoint)pulseWave0.getSpecialPoints()[j]);
                                if (spj.getType() == SpecialPoint.TYPE_BOTTOM && spj.getPosition() > sp.getPosition())
                                {
                                    sp0 = spj;
                                    break;
                                }
                            }
                            tb.Text = sp.getPosition() + "\r\nArm length is " + armLength +
                                "M\r\nPWV is " + armLength * 200 / (sp0.getPosition() - sp.getPosition());
                        }
                        Canvas.SetTop(tb, baseLine1 - (short)pulseDataArray1[sp.getPosition()]);
                        Canvas.SetLeft(tb, xValue + 5);
                        this.tba.Add(tb);
                        this.pulseCanvas.Children.Add(tb);
                        this.pulseCanvas.Children.Add(aLine);
                    }
                }
            }
        }

        public void drawWaves()
        {
            clearLines();
            if (this.pulseDataArray0.Count > pulseCanvas.Width)
            {
                drawWave(0);
            }
            if (this.pulseDataArray1 != null && this.pulseDataArray1.Count > 0)
            {
                drawWave(1);
                Console.WriteLine("draw line 1");
            }
            if (this.pulseDataArray2 != null && this.pulseDataArray2.Count > 0)
            {
                drawWave(2);
                Console.WriteLine("draw line 2");
            }
        }

        public void drawSegments()
        {
            if (!isMonitoring0 && !isMonitoring1)
            {
                if (this.path0 != null && this.path0.IsLoaded)
                {
                    this.pulseCanvas.Children.Remove(path0);
                }
                if (this.path1 != null && this.path1.IsLoaded)
                {
                    this.pulseCanvas.Children.Remove(path1);
                }
                clearLines();
                if (this.pulseDataArray0.Count > pulseCanvas.Width && currentStart > 0)
                {
                    drawWaveSegment(0, currentStart, currentRate);
                }
                if (pulseDataArray1 != null && this.pulseDataArray1.Count > pulseCanvas.Width && currentStart > 0)
                {
                    drawWaveSegment(1, currentStart, currentRate);
                }
            }
        }

        private void mouseDown(object sender, MouseButtonEventArgs e)
        {
        }

        private void saveButton_Click(object sender, RoutedEventArgs e)
        {
            NavigationService.Navigate(new Uri("Index.xaml", UriKind.Relative));
        }

        private void setDTW()
        {
            if (this.pulseWave0 != null && pulseWave0.getPulseDataArray()!=null && pulseWave0.getPulseDataArray().Count>0)
            {
                int selectIndex = 0;
                for (int i = 0; i < pulseSamples.Length;i++ )
                {
                    PulseWave pulseWaveSample = pulseSamples[i];
                    double distance = pulseWave0.getDTWDistance(pulseWaveSample);
                    if (distance < pulseWave0.DTWDistance)
                    {
                        pulseWave0.DTWDistance = distance;
                        pulseWave0.description = pulseWaveSample.description;
                        pulseWave2 = pulseWaveSample;
                        pulseDataArray2 = pulseWave2.getFirstWaveformDataArray();
                        this.DTWSelection = i;
                        selectIndex = i;
                    }
                }
                this.labelSimilar.Text = "This type of wave form is at " + pulseSamples[selectIndex].description;
                Canvas.SetLeft(labelSimilar, pulseDataArray2.Count + 20);
            }
        }

        private void dataGrid1_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (this.dataGrid1.Items.Count > 0 && clicked)
            {
                pulseDataSet.monitoringRow currentRow = myDataSet.monitoring.NewmonitoringRow();
                currentRow = (pulseDataSet.monitoringRow)dataGrid1.SelectedItem;
                if (currentRow.pulse_data != null)
                {
                    pulseWave0 = new PulseWave((byte[])currentRow.pulse_data, CommonResources.Instance.getPerson().getHeight());
                    pulseDataArray0 = pulseWave0.getPulseDataArray();
                    pulseWave0.getSIs();
                    setDTW();
                    
                    
                    this.pulseCanvas.Children.Remove(path0);
                    this.pulseCanvas.Children.Remove(path2);
                    drawWaves();
                    this.resultTextBlock.Text = CommonResources.Instance.getPerson().toResult()+ "\r\n" + pulseWave0.toResult();
                    //resultTextBlock.Text += "\r\nselected item: " + dataGrid1.SelectedValue; 
                }
                //clicked = false;
            }
        }

        


	}
}
